package com.popo.android;

import java.util.List;

import android.database.SQLException;
import android.os.Bundle;
import android.widget.TextView;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.popo.android.db.DataBaseHelper;
import com.popo.android.entity.UserEntity;

public class MyOrmLite extends OrmLiteBaseActivity<DataBaseHelper> {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test1);
		TextView tv = (TextView) findViewById(R.id.tv);

		//
		OrmLiteSqliteOpenHelper helper = getHelper();

		RuntimeExceptionDao<UserEntity, Integer> userDao = helper
				.getRuntimeExceptionDao(UserEntity.class);

		UserEntity userOne = new UserEntity("one", "onepass", "beijing one",
				"13511111111", "one company");
		userDao.create(userOne);

		List<UserEntity> list = null;
		try {
			list = userDao.query(userDao.queryBuilder().prepare());
		} catch (java.sql.SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		StringBuffer tvtext = new StringBuffer();
		if (list.size() > 0) {
			for (UserEntity user : list) {
				tvtext.append(user.getName() + "\n\tid:\t" + user.get_id()
						+ "\n");
				tvtext.append("\tpass:\t" + user.getPass() + "\n");
				tvtext.append("\tphone\n" + user.getPhone() + "\n");
				tvtext.append("\n\n");
			}
		} else {
			tvtext.append("no data");
		}
		tv.setText(tvtext);
	}

}
